package org.gd.exercise.learnspringbootredis.resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisResource {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

//    @GetMapping("/storeUser")
//    public String storeUser() {
//        redisTemplate.opsForValue().set("jys_user:80801", "admin");
//        return redisTemplate.opsForValue().get("jys_user:80801").toString();
//    }

    @GetMapping("/storeUser")
    public Object storeUser() {
        redisTemplate.opsForValue().set("jys_user:80801", "用户");
        return redisTemplate.opsForValue().get("jys_user:80801");
    }

    @GetMapping("/stoteUser1")
    public String storeUser1() {
        stringRedisTemplate.opsForValue().set("jys_user:80802", "admin_str");
        return stringRedisTemplate.opsForValue().get("jys_user:80802");
    }

    @GetMapping("/test")
    public String test() {
        return "test";
    }
}
